﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.CiZhiTuiXiuServiceReference;

namespace CommunitySystem
{
    public partial class CiZhiDateWindow : ChildWindow
    {
        public DateTime? Dt = null;
        public int ID;
        public string Type;
        private CiZhiTuiXiuServiceClient _Client = new CiZhiTuiXiuServiceClient();
        public CiZhiDateWindow(int id,string type)
        {
            InitializeComponent();
            Type = type;
            _Client.UpdateCiZhiStatusCompleted += new EventHandler<UpdateCiZhiStatusCompletedEventArgs>(_Client_UpdateCiZhiStatusCompleted);
            ID = id;
        }

        void _Client_UpdateCiZhiStatusCompleted(object sender, UpdateCiZhiStatusCompletedEventArgs e)
        {
            SilverlightMessageBoxLibrary.Message.InfoMessage("确认成功！");
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(riqi.Text) || Convert.ToDateTime(riqi.Text) == Convert.ToDateTime("1900-01-01"))
            {
                SilverlightMessageBoxLibrary.Message.ErrorMessage("请填写确认日期！");
                return;
            }
            if (MessageBox.Show("确认审核通过吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Dt = Convert.ToDateTime(riqi.Text);
                if(Type == "辞职") _Client.UpdateCiZhiStatusAsync(ID, Dt);
                if (Type == "退休") _Client.UpdateTuiXiuStatusAsync(ID, Dt);
                this.DialogResult = true;
            }
            
        }
    }
}
